import GameDefine from "./GameDefine";
import { Game } from "./Game";
import { showHome } from "./Home";
class Main {
	constructor() {
		//根据IDE设置初始化引擎		
		if (window["Laya3D"]) Laya3D.init(GameDefine.width, GameDefine.height);
		else Laya.init(GameDefine.width, GameDefine.height, Laya["WebGL"]);
		Laya["Physics"] && Laya["Physics"].enable();
		Laya["DebugPanel"] && Laya["DebugPanel"].enable();
		Laya.stage.scaleMode = GameDefine.scaleMode;
		Laya.stage.screenMode = GameDefine.screenMode;
		Laya.stage.alignV = GameDefine.alignV;
		Laya.stage.alignH = GameDefine.alignH;
		//兼容微信不支持加载scene后缀场景
		Laya.URL.exportSceneToJson = GameDefine.exportSceneToJson;

		//打开调试面板（通过IDE设置调试模式，或者url地址增加debug=true参数，均可打开调试面板）
		if (GameDefine.debug || Laya.Utils.getQueryString("debug") == "true") Laya.enableDebugPanel();
		if (GameDefine.physicsDebug && Laya["PhysicsDebugDraw"]) Laya["PhysicsDebugDraw"].enable();
		if (GameDefine.stat) Laya.Stat.show();
		Laya.alertGlobalError = true;

		// 这里是游戏具体代码
		this._startGame()
	}
	private _startGame() {
		fgui.UIConfig.packageFileExtension = 'bin';
		Laya.stage.addChild(fgui.GRoot.inst.displayObject);
		fgui.GRoot.inst.height = Laya.stage.height;
		fgui.GRoot.inst.width = Laya.stage.width;

		let urls = [{ url: 'res/fgui/home.bin', type: Laya.Loader.BUFFER }]
		Laya.loader.load(urls, Laya.Handler.create(this, () => {
			fgui.UIPackage.addPackage("res/fgui/home");
			showHome();
		}))


	}

}
//激活启动类
new Main();
